var gBookmarkTree;
var gOK;
var gUrls;

function Startup() {
	initServices();
	initBMService();
	gOK = document.documentElement.getButton('accept');
	gBookmarkTree = document.getElementById('bookmarks-view');
	gBookmarkTree.treeBoxObject.view.selection.select(0);
	gBookmarkTree.focus();
}

function onDblClick() {
	if (!gOK.disabled) {
		document.documentElement.acceptDialog();
	}
}

function updateOK() {
	var selection = gBookmarkTree._selection;
	var ds = gBookmarkTree.tree.database;
	var url;

	gUrls = [];

	for (var i = 0; i<selection.length; ++i) {
		var type = selection.type[i];

		if (type == 'Bookmark' || type == '') {
			url = BookmarksUtils.getProperty(selection.item[i], gNC_NS + 'URL', ds);

			if (url) {
				gUrls.push(url);
			}
    		}
	}

	gOK.disabled = gUrls.length == 0;
}

function onOK(aEvent) {
	window.arguments[0].url = gUrls.join("|");
}
